package chapter05_array;

/**
 * ClassName: SelectArray01
 * Package: chapter05_array
 * Description:
 *定义数组 int[] arr=new int[]{34,54,3,2,65,7,34,5,76,34};
 * 查找数字5是否在上述元素中出现过？如果出现了，输出其下标
 * @Author 安思宇
 * @Create 2025/2/26 18:41
 */
public class SelectArray01 {
    public static void main(String[] args) {
        //定义数组及临时变量
         int[] arr=new int[]{34,54,3,2,65,7,34,5,76,34};
         int temp=0;
         boolean flag=true;
         //写for循环依次查找
        for (int i = 0; i < arr.length; i++) {
            if(arr[i]==5){
                temp=i;
                System.out.println(temp);
                flag=false;
                break;
            }
        }
        //输出临时变量
        if (flag) {
            System.out.println("未找到。");
        }
    }
}
